﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Chart3D;
using FEM.Basic;
using Newtonsoft.Json;
using PGMHelper;
using YJKTXT;

namespace CloundModelPrj
{
    /// <summary>
    /// 单体结构
    /// </summary>
    public class SingleModel
    {
        /// <summary>
        /// 弹塑性模型
        /// </summary>
        private FEM_Model model { set; get; }

        /// <summary>
        /// 结构信息
        /// </summary>
        private StructuralInfo structInfo { set; get; }

        /// <summary>
        /// 结构体系
        /// </summary>
        private string StructSystem
        {
            get
            {
                return FEM_Model.GetSystemDescp(model.StructSystem);
            }
        }

        /// <summary>
        /// 结构体系
        /// </summary>
        public int StructSystemInt
        {
            get
            {
                return Convert.ToInt32(this.model.ParamDict[101]);
            }
        }

        /// <summary>
        /// 振型信息
        /// </summary>
        private List<string> wzqTXT
        {
            get
            {
                //判断起始序号
                int startIndex = this.model.YJK_Txt_Info.Count == 5 ? 0 : 1;
                return this.model.YJK_Txt_Info[startIndex + 1];
            }
        }

        /// <summary>
        /// 结构高度
        /// </summary>
        private int modelHeight
        {
            get
            {
                return this.model.Height;
            }
        }

        /// <summary>
        /// X向长度
        /// </summary>
        private int XLength
        {
            get
            {
                return this.model.XLength;
            }
        }

        /// <summary>
        /// Y向长度
        /// </summary>
        private int YLength
        {
            get
            {
                return this.model.YLength;
            }
        }

        /// <summary>
        /// 遍历节点Demo
        /// </summary>
        private void NodeForeachDemo()
        {
            //地下室层数
            var baseNumber = this.model.Basement_Num;
            //遍历模型节点
            this.model.Node_List.ForEach(node =>
            {
                //坐标
                var x = node.X;
                var y = node.Y;
                var z = node.Z;
                //楼层
                var storeyIndex = node.Storey_Index;
                //塔楼
                var towerIndex = node.Tower_Index;
            });
        }

        /// <summary>
        /// 绘图对象
        /// </summary>
        public Chart3DMain GetChart3DMain(Control control)
        {
            //构造图片
            return this.model.GetChart3D(control);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="directPath"></param>
        public SingleModel(string directPath)
        {
            //读取文件信息
            string zipJson = File.ReadAllText(string.Format("{0}\\WW_Info.txt", directPath));
            //序列化
            this.model = JsonConvert.DeserializeObject<FEM_Model>(ZipHelper.DecompressString(zipJson));
        }
    }
}
